package Graph;

import java.util.Scanner;

public class 水流问题 {
    static int m;
    static int n;
    static int[][] graph;
    static boolean border1Flag = false;
    static boolean border2Flag = false;
    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

    /*public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        graph = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs(i, j, new boolean[n][m]);
                if (border1Flag && border2Flag) {
                    System.out.println(i + " " + j);
                }
                border1Flag = false;
                border2Flag = false;
            }
        }
    }

    private static void dfs (int i, int j, boolean[][] visited) {
        if (i == 0 || j == 0) {
            border1Flag = true;
        }
        if (i == n - 1 || j == m - 1) {
            border2Flag = true;
        }
        visited[i][j] = true;
        for (int[] d : dir) {
            int nextI = i + d[0];
            int nextJ = j + d[1];
            if (nextI < 0 || nextI >= n || nextJ < 0 || nextJ >= m || visited[nextI][nextJ] || graph[nextI][nextJ] > graph[i][j]) {
                continue;
            }
            dfs(nextI, nextJ, visited);
        }
    }*/

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        m = sc.nextInt();
        n = sc.nextInt();
        graph = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                graph[i][j] = sc.nextInt();
            }
        }
        boolean[][] border1 = new boolean[m][n];
        boolean[][] border2 = new boolean[m][n];
        for (int i = 0; i < m; i++) {
            dfs(i, 0, border1);
            dfs(i, n - 1, border2);
        }
        for (int j = 0; j < n; j++) {
            dfs(0, j, border1);
            dfs(m - 1, j, border2);
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (border1[i][j] && border2[i][j]) {
                    System.out.println(i + " " + j);
                }
            }
        }
    }

    private static void dfs (int x, int y, boolean[][] visited) {
        visited[x][y] = true;
        for (int[] d : dir) {
            int nextX = x + d[0];
            int nextY = y + d[1];
            if (nextX < 0 || nextX >= m || nextY < 0 || nextY >= n || visited[nextX][nextY] || graph[nextX][nextY] < graph[x][y]) {
                continue;
            }
            dfs(nextX, nextY, visited);
        }
    }
}